<?php 
class candidateApplyAction extends AdminMaster{
	public function execute($request){
		
		$candidate = CandidatesTable::getDataById($this->data['id']);		
		if($this->data['action'] == ADMIN_DEFINED::AJAX_APPLY && count($candidate) > 0){
			$this->data['history'] = CandidateToJobsTable::getListByCandidateId($this->data['id']);
			$this->data['companies'] = CompaniesTable::getDataList(array(), array());
		}elseif($this->data['action'] == ADMIN_DEFINED::AJAX_APPLY_SEARCH){
			$json = array('status' => '1', 'data' => array(), 'id' => $this->data['id'], 'history' => array());
			
			$data['filter_key'] = $request->getParameter('search_key', '');
			$data['filter_company_id'] = $request->getParameter('company_id', -1);
			$data['filter_date_from'] = $request->getParameter('date_from', '');
			$data['filter_date_to'] = $request->getParameter('date_to', '');
				
			$json['data'] = JobsTable::getDataList($data, array());
			$his = CandidateToJobsTable::getListByCandidateId($this->data['id']);
			$his_job_ids = array('-1');
			foreach($his as $h){
				$his_job_ids[] = $h['job_id'] ;
			}
			$json['history'] = $his_job_ids;
			print_r(json_encode($json));
			return sfView::NONE;
		}else{
			$this->data['error'] = __('hacking_attemp',null,'table_list');
		}
		$this->setVar('data', $this->data);
	}
}